package graphmanip.thinning;


import graphmanip.ThinningMethod;

import java.awt.Point;
import java.util.ArrayList;

import commonfunctions.Matrix;

public class BetweennessThinning extends ThinningMethod
{
	public ArrayList<Point> thinGraph(Matrix weights) {
		Matrix betweenness = new Matrix(weights.length());
		ArrayList<Point> edges = new ArrayList<Point>();
		ArrayList<Integer> nodes = new ArrayList<Integer>();
		for (int i = 0; i < weights.length(); i++)
			nodes.add(i);
		for (int i = 0; i < weights.length(); i++)
		{
			for (int j = 0; j < weights.length(); j++)
			{
				if (weights.get(i, j) > 0.0)
					edges.add(new Point(i, j));
			}
		}
		System.out.println(edges.size() + " edges.");
		
		FlowCalc.calculate(betweenness, weights, edges, nodes);
		
		Point maxEdge = new Point(0, 0);
		
		for (int i = 0; i < betweenness.length(); i++)
		{
			for (int j = 0; j < betweenness.length(); j++)
			{
				if (betweenness.get(i, j) > betweenness.get(maxEdge.x, maxEdge.y))
					maxEdge = new Point(i, j);
			}
		}
		ArrayList<Point> toReturn = new ArrayList<Point>();
		toReturn.add(maxEdge);
		
		return toReturn;
	}
}
